//
//  HNDoctorDetailViewController.m
//  JHFBaseProject
//
//  Created by 朱传正 on 2016/12/14.
//  Copyright © 2016年 好牛. All rights reserved.
//

#import "HNDoctorDetailViewController.h"
#import "NSString+Size.h"
#import "HNQuickServiceController.h"
@interface HNDoctorDetailViewController ()

@property (nonatomic,assign) CGFloat contentHeight;

@property (nonatomic,strong) NSDictionary *detailDic;
@property (nonatomic,strong) NSMutableArray *commentListArr;

@property (nonatomic,strong) UIScrollView *xContentScrollView;

@property (nonatomic,assign) NSInteger isCollect;


@property (nonatomic,strong) UILabel *connectNumLabel;

@end

@implementation HNDoctorDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.concernBtn.selected = NO;
    
   
}
- (IBAction)quickAction:(UIButton *)sender {
    
    HNQuickServiceController *quickServiceVC = [[HNQuickServiceController alloc]init];
    quickServiceVC.userId = _userId;
    [self.navigationController pushViewController:quickServiceVC animated:YES];
}


- (IBAction)concernBtn:(UIButton *)sender {
    _concernBtn.enabled = NO;
    if (_isCollect) {
        [self deleteConcern];
    }else{
        [self addConcern];
    }
}

-(void)drawView{
    self.title = @"医生详情";
    self.quickBtn.backgroundColor = RGB(85, 206, 84);
    _contentHeight = 0;
    _commentListArr = [NSMutableArray array];
    
    _xContentScrollView = [[UIScrollView alloc]initWithFrame:_contentScrollView.frame];
    
    [_contentScrollView addSubview:_xContentScrollView];
//    [self createContentScrollView];
    
    UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 0.5)];
    lineLabel.backgroundColor = [UIColor grayColor];
    [self.view addSubview:lineLabel];
    
}

-(void)initData{
    [self getDoctorDetail];
}

-(void)createContentScrollView{
    //头部医生照片
    UIImageView *doctorView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, kScreen_Width*4/5)];
    [doctorView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",url_Base,[_detailDic objectForKey:@"photo"]]] placeholderImage:[UIImage imageNamed:@"D99GN4P63Q4F.png"]];
    [self.xContentScrollView addSubview:doctorView];
    
    
    //重设contentScrollView.contentSize
    _contentHeight = _contentHeight + doctorView.frame.size.height + 15;
    _xContentScrollView.contentSize = CGSizeMake(kScreen_Width, _contentHeight);
    
    //医生姓名
    UILabel *nameLabel = [[UILabel alloc]init];
    nameLabel.numberOfLines = 1;
    nameLabel.clipsToBounds = YES;
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.font = [UIFont systemFontOfSize:14];
    nameLabel.backgroundColor = [UIColor whiteColor];
    nameLabel.textColor = RGBJ(45);
    NSString *realName = [NSString stringWithFormat:@"%@",[_detailDic objectForKey:@"realName"]];
    NSString *nickname = [NSString stringWithFormat:@"%@",[_detailDic objectForKey:@"nickname"]];
    NSString *username = [NSString stringWithFormat:@"%@",[_detailDic objectForKey:@"username"]];
    if ([AppConfig isNULL:nickname]) {
        if ([AppConfig isNULL:realName]){
            nameLabel.text = username;
        }else{
            nameLabel.text = realName;
        }
    }else {
        nameLabel.text = nickname;
    }
//    CGFloat nameLabelLength = nameLabel.text.length * 15;
    nameLabel.frame = CGRectMake(10,_contentHeight, kScreen_Width/4.0,20);
    [_xContentScrollView addSubview:nameLabel];
    
    //标题
    UILabel *oNameLabel = [[UILabel alloc]init];
    oNameLabel.numberOfLines = 1;
    oNameLabel.clipsToBounds = YES;
    oNameLabel.layer.cornerRadius = 4;
    oNameLabel.textAlignment = NSTextAlignmentLeft;
    oNameLabel.font = [UIFont systemFontOfSize:14];
    oNameLabel.backgroundColor = [UIColor whiteColor];
    oNameLabel.textColor = RGBJ(69);
    oNameLabel.text = [NSString stringWithFormat:@"%@",[_detailDic objectForKey:@"professionalTitleName"]];
    CGFloat oNameLabelLength = oNameLabel.text.length * 15;
    oNameLabel.frame = CGRectMake(nameLabel.frame.origin.x + nameLabel.frame.size.width + 5,_contentHeight, oNameLabelLength,20);
    [_xContentScrollView addSubview:oNameLabel];
    
    //成交
    UILabel *rightLabel1 = [[UILabel alloc]init];
    rightLabel1.numberOfLines = 1;
    rightLabel1.clipsToBounds = YES;
    rightLabel1.layer.cornerRadius = 4;
    rightLabel1.textAlignment = NSTextAlignmentLeft;
    rightLabel1.font = [UIFont systemFontOfSize:12];
    rightLabel1.backgroundColor = [UIColor whiteColor];
    rightLabel1.textColor = RGBJ(69);
    NSString *tradeCount = [NSString stringWithFormat:@"%@",[_detailDic objectForKey:@"tradeCount"]];
    if ([AppConfig isNULL:tradeCount]) {
        tradeCount = @"0";
    }
    rightLabel1.text = tradeCount;
    CGFloat length1 = rightLabel1.text.length * 8;
    rightLabel1.frame = CGRectMake(kScreen_Width - 10 - length1, _contentHeight, length1, 20);
    [_xContentScrollView addSubview:rightLabel1];
    
    
    UILabel *rightLabel2 = [[UILabel alloc]init];
    rightLabel2.numberOfLines = 1;
    rightLabel2.clipsToBounds = YES;
    rightLabel2.layer.cornerRadius = 4;
    rightLabel2.textAlignment = NSTextAlignmentLeft;
    rightLabel2.font = [UIFont systemFontOfSize:12];
    rightLabel2.backgroundColor = [UIColor whiteColor];
    rightLabel2.textColor = RGBJ(69);
    rightLabel2.text = @"成交";
    CGFloat length2 = rightLabel2.text.length * 13;
    rightLabel2.frame = CGRectMake(rightLabel1.frame.origin.x - 5 - length2 , _contentHeight, length2, 20);
    [_xContentScrollView addSubview:rightLabel2];
    
    UIImageView *rightImageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(rightLabel2.frame.origin.x - 25, _contentHeight, 20, 20)];
    rightImageView1.image = [UIImage imageNamed:@"千库网-成交-(1).png"];
    [_xContentScrollView addSubview:rightImageView1];
    
    //关注
    _connectNumLabel = [[UILabel alloc]init];
    _connectNumLabel.numberOfLines = 1;
    _connectNumLabel.clipsToBounds = YES;
    _connectNumLabel.layer.cornerRadius = 4;
    _connectNumLabel.textAlignment = NSTextAlignmentLeft;
    _connectNumLabel.font = [UIFont systemFontOfSize:12];
    _connectNumLabel.backgroundColor = [UIColor whiteColor];
    _connectNumLabel.textColor = RGBJ(69);
    NSString *collectCount = [NSString stringWithFormat:@"%@",[_detailDic objectForKey:@"collectCount"]];
    if ([AppConfig isNULL:collectCount]) {
        collectCount = @"0";
    }
    _connectNumLabel.text = collectCount;
    CGFloat length3 = _connectNumLabel.text.length * 8;
    _connectNumLabel.frame = CGRectMake(rightImageView1.frame.origin.x - 10 - length3, _contentHeight, length3, 20);
    [_xContentScrollView addSubview:_connectNumLabel];
    
    
    UILabel *rightLabel4 = [[UILabel alloc]init];
    rightLabel4.numberOfLines = 1;
    rightLabel4.clipsToBounds = YES;
    rightLabel4.layer.cornerRadius = 4;
    rightLabel4.textAlignment = NSTextAlignmentLeft;
    rightLabel4.font = [UIFont systemFontOfSize:12];
    rightLabel4.backgroundColor = [UIColor whiteColor];
    rightLabel4.textColor = RGBJ(69);
    rightLabel4.text = @"关注";
    CGFloat length4 = rightLabel4.text.length * 13;
    rightLabel4.frame = CGRectMake(_connectNumLabel.frame.origin.x - 5 - length4 , _contentHeight, length4, 20);
    [_xContentScrollView addSubview:rightLabel4];
    
    UIImageView *rightImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(rightLabel4.frame.origin.x - 25, _contentHeight, 20, 20)];
    rightImageView2.image = [UIImage imageNamed:@"552cc3c60065d_128.png"];
    [_xContentScrollView addSubview:rightImageView2];
    
    
    //重设contentScrollView.contentSize
    _contentHeight = _contentHeight + nameLabel.frame.size.height + 10;
    _xContentScrollView.contentSize = CGSizeMake(kScreen_Width, _contentHeight);
    
    
//    UILabel *doctorDetailLabel = [[UILabel alloc]init];
//    doctorDetailLabel.numberOfLines = 0;
//    doctorDetailLabel.clipsToBounds = YES;
//    doctorDetailLabel.layer.cornerRadius = 4;
//    doctorDetailLabel.textAlignment = NSTextAlignmentLeft;
//    doctorDetailLabel.font = [UIFont systemFontOfSize:14];
//    doctorDetailLabel.backgroundColor = [UIColor whiteColor];
//    doctorDetailLabel.textColor = RGBJ(69);
//    doctorDetailLabel.text = [NSString stringWithFormat:@"%@",[_detailDic objectForKey:@"flag3"]];
//    CGFloat doctorDetailHeight = doctorDetailLabel.text.length>0 ?[doctorDetailLabel.text heightWithFont:[UIFont systemFontOfSize:14.0f] constrainedToWidth:((kScreen_Width - 20) )] : 0;
//    doctorDetailLabel.frame = CGRectMake(10, _contentHeight, kScreen_Width - 20, doctorDetailHeight);
//    
//    [_xContentScrollView addSubview:doctorDetailLabel];
//    
//    
//    //重设contentScrollView.contentSize
//    _contentHeight = _contentHeight + doctorDetailLabel.frame.size.height + 10;
//    _xContentScrollView.contentSize = CGSizeMake(kScreen_Width, _contentHeight);
    
    //间隙View
    UIView *gapView = [[UIView alloc]initWithFrame:CGRectMake(0, _contentHeight,kScreen_Width, 5)];
    
    gapView.backgroundColor = RGB(236, 240, 241);
    [_xContentScrollView addSubview:gapView];
    
    //重设contentScrollView.contentSize
    _contentHeight = _contentHeight + gapView.frame.size.height + 5;
    _xContentScrollView.contentSize = CGSizeMake(kScreen_Width, _contentHeight);
    
    //医生介绍
    
    UIImageView *doctorIconView = [[UIImageView alloc]initWithFrame:CGRectMake(10, _contentHeight, 20, 20)];
    doctorIconView .image = [UIImage imageNamed:@"552cd0e23b1e0_128.png"];
    [_xContentScrollView addSubview:doctorIconView ];

    UILabel *introduceLabel = [[UILabel alloc]init];
    introduceLabel.numberOfLines = 1;
    introduceLabel.clipsToBounds = YES;
    introduceLabel.layer.cornerRadius = 4;
    introduceLabel.textAlignment = NSTextAlignmentLeft;
    introduceLabel.font = [UIFont systemFontOfSize:15];
    introduceLabel.backgroundColor = [UIColor whiteColor];
    introduceLabel.textColor = RGBJ(69);
    introduceLabel.text = @"医生介绍";
    introduceLabel.frame = CGRectMake(doctorIconView.frame.origin.x + doctorIconView.frame.size.width + 5,_contentHeight, 150,20);
    [_xContentScrollView addSubview:introduceLabel];

    //重设contentScrollView.contentSize
    _contentHeight = _contentHeight + doctorIconView.frame.size.height + 5;
    _xContentScrollView.contentSize = CGSizeMake(kScreen_Width, _contentHeight);
    
    //医生介绍详情
    UILabel *introduceDetailLabel = [[UILabel alloc]init];
    introduceDetailLabel.numberOfLines = 0;
    introduceDetailLabel.clipsToBounds = YES;
    introduceDetailLabel.layer.cornerRadius = 4;
    introduceDetailLabel.textAlignment = NSTextAlignmentLeft;
    introduceDetailLabel.font = [UIFont systemFontOfSize:14];
    introduceDetailLabel.backgroundColor = [UIColor whiteColor];
    introduceDetailLabel.textColor = RGBJ(69);
    introduceDetailLabel.text = [NSString stringWithFormat:@"%@",[_detailDic objectForKey:@"flag1"]];
    CGFloat introduceDetailHeight = introduceDetailLabel.text.length>0 ?[introduceDetailLabel.text heightWithFont:[UIFont systemFontOfSize:14.0f] constrainedToWidth:((kScreen_Width - 20) )] : 0;
    introduceDetailLabel.frame = CGRectMake(10, _contentHeight, kScreen_Width - 20, introduceDetailHeight);
    [_xContentScrollView addSubview:introduceDetailLabel];
    
    //重设contentScrollView.contentSize
    _contentHeight = _contentHeight + introduceDetailLabel.frame.size.height + 5;
    _xContentScrollView.contentSize = CGSizeMake(kScreen_Width, _contentHeight);
    
    NSInteger isCollect = [[NSString stringWithFormat:@"%@",[_detailDic objectForKey:@"isCollect"]] integerValue];
    _isCollect = isCollect;
    if (isCollect == 0) {
        [_concernImage setHighlighted:NO];
    }else{
        [_concernImage setHighlighted:YES];
    }
    
    [self getCommentListData];
  
}

-(void)createCommentList{
    //间隙View
    UIView *gapView2 = [[UIView alloc]initWithFrame:CGRectMake(0, _contentHeight,kScreen_Width, 5)];
    
    gapView2.backgroundColor = RGB(236, 240, 241);
    [_xContentScrollView addSubview:gapView2];
    
    //重设contentScrollView.contentSize
    _contentHeight = _contentHeight + gapView2.frame.size.height + 5;
    _xContentScrollView.contentSize = CGSizeMake(kScreen_Width, _contentHeight);
    
    //医生介绍
    
    UIImageView *priceIconView = [[UIImageView alloc]initWithFrame:CGRectMake(10, _contentHeight, 20, 20)];
    priceIconView .image = [UIImage imageNamed:@"message.png"];
    [_xContentScrollView addSubview:priceIconView ];
    
    UILabel *priceLabel = [[UILabel alloc]init];
    priceLabel.numberOfLines = 1;
    priceLabel.clipsToBounds = YES;
    priceLabel.layer.cornerRadius = 4;
    priceLabel.textAlignment = NSTextAlignmentLeft;
    priceLabel.font = [UIFont systemFontOfSize:15];
    priceLabel.backgroundColor = [UIColor whiteColor];
    priceLabel.textColor = RGBJ(69);
    priceLabel.text = [NSString stringWithFormat:@"评价（%ld）",_commentListArr.count];
    priceLabel.frame = CGRectMake(priceIconView.frame.origin.x + priceIconView.frame.size.width + 5,_contentHeight, 150,20);
    [_xContentScrollView addSubview:priceLabel];
    
    if (_commentListArr.count < 1) {
        return;
    }
    
    //重设contentScrollView.contentSize
    _contentHeight = _contentHeight + priceIconView.frame.size.height + 5;
    _xContentScrollView.contentSize = CGSizeMake(kScreen_Width, _contentHeight);
    
    for (int i = 0; i < _commentListArr.count; i++) {
        NSDictionary *commentDic = [NSDictionary dictionaryWithDictionary:_commentListArr[i]];
        UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, _contentHeight, kScreen_Width-10, 1)];
        lineLabel.backgroundColor = [UIColor colorWithHexString:@"cecece"];
        [_xContentScrollView addSubview:lineLabel];
        
        _contentHeight = _contentHeight + 5;
        
        UIImageView *pricePeopleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, _contentHeight, 46, 46)];
        pricePeopleImageView.layer.masksToBounds = YES;
        pricePeopleImageView.layer.cornerRadius = 23;
        NSString *imageStr = [NSString stringWithFormat:@"%@%@",url_Base,[commentDic objectForKey:@"photo"]];
        [pricePeopleImageView sd_setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:[UIImage imageNamed:@"Photo.png"]];
        [_xContentScrollView addSubview:pricePeopleImageView];
        
        UILabel *pricePeopleNameLabel = [[UILabel alloc]init];
        pricePeopleNameLabel.numberOfLines = 1;
        pricePeopleNameLabel.clipsToBounds = YES;
        pricePeopleNameLabel.layer.cornerRadius = 4;
        pricePeopleNameLabel.textAlignment = NSTextAlignmentLeft;
        pricePeopleNameLabel.font = [UIFont systemFontOfSize:14];
        pricePeopleNameLabel.backgroundColor = [UIColor whiteColor];
        pricePeopleNameLabel.textColor = RGBJ(69);
        NSString *nickname = [NSString stringWithFormat:@"%@",[commentDic objectForKey:@"realName"]];
        NSString *mobile = [NSString stringWithFormat:@"%@",[commentDic objectForKey:@"mobile"]];
        if ([AppConfig isNULL:nickname]) {
            pricePeopleNameLabel.text = mobile;
        }else{
            pricePeopleNameLabel.text = nickname;
        }
       
        pricePeopleNameLabel.frame = CGRectMake(60,_contentHeight, 200,23);
        [_xContentScrollView addSubview:pricePeopleNameLabel];
        
        UILabel *pricePeopleTimeLabel = [[UILabel alloc]init];
        pricePeopleTimeLabel.numberOfLines = 1;
        pricePeopleTimeLabel.clipsToBounds = YES;
        pricePeopleTimeLabel.layer.cornerRadius = 4;
        pricePeopleTimeLabel.textAlignment = NSTextAlignmentLeft;
        pricePeopleTimeLabel.font = [UIFont systemFontOfSize:11];
        pricePeopleTimeLabel.backgroundColor = [UIColor whiteColor];
        pricePeopleTimeLabel.textColor = RGBJ(69);
        pricePeopleTimeLabel.text = [NSString stringWithFormat:@"%@",[commentDic objectForKey:@"createTime"]];
        pricePeopleTimeLabel.frame = CGRectMake(60,_contentHeight + 23, 200,23);
        [_xContentScrollView addSubview:pricePeopleTimeLabel];
        
        
        _contentHeight = _contentHeight + 3;
        
        UILabel *priceDetailLabel = [[UILabel alloc]init];
        priceDetailLabel.numberOfLines = 0;
        priceDetailLabel.clipsToBounds = YES;
        priceDetailLabel.layer.cornerRadius = 4;
        priceDetailLabel.textAlignment = NSTextAlignmentLeft;
        priceDetailLabel.font = [UIFont systemFontOfSize:14];
        priceDetailLabel.backgroundColor = [UIColor whiteColor];
        priceDetailLabel.textColor = RGBJ(69);
        priceDetailLabel.text = [NSString stringWithFormat:@"%@",[commentDic objectForKey:@"content"]];
        CGFloat priceDetailHeight = priceDetailLabel.text.length>0 ?[priceDetailLabel.text heightWithFont:[UIFont systemFontOfSize:14.0f] constrainedToWidth:((kScreen_Width - 20) )] : 0;
        priceDetailLabel.frame = CGRectMake(10, _contentHeight + 46, kScreen_Width - 20, priceDetailHeight);
        [_xContentScrollView addSubview:priceDetailLabel];
        
        
        //重设contentScrollView.contentSize
        _contentHeight = _contentHeight + pricePeopleImageView.frame.size.height + priceDetailLabel.frame.size.height + 5;
        _xContentScrollView.contentSize = CGSizeMake(kScreen_Width, _contentHeight);
    }
    

}



#pragma mark - 初始化医生详情
-(void)getDoctorDetail{
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:_userId,@"userId",nil];
    
    [param setObject:static_sessionId forKey:@"sessionId"];
    NSLog(@"param = %@",param);
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_doctor_detail parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSLog(@"responseObject = %@",responseObject);
        
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            [self showHint:@"获取医生详情失败"];
            NSLog(@"==dict:%@",data);
            return;
        }
        NSLog(@"==dict:%@",data);
        
        NSString * result = [NSString stringWithFormat:@"%@",[data objectForKey:@"result"]];
        if ([result isEqualToString:@"1"]) {
            _detailDic = [NSDictionary dictionaryWithDictionary:[data objectForKey:@"obj"]];
            NSLog(@"------obj = %@",_detailDic);
            
            [_xContentScrollView removeFromSuperview];
            _xContentScrollView = [[UIScrollView alloc]initWithFrame:_contentScrollView.frame];
            [_contentScrollView addSubview:_xContentScrollView];
            _contentHeight = 0;
            [self createContentScrollView];
            
        }else{
            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"msg"]];
            if ([info isEqualToString:msg_InvalidLoginInformation]) {
                
                [AppConfig removeUserInfo];
                
                [[EMClient sharedClient] logout:YES];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
                
                LoginViewController *loginVC = [[LoginViewController alloc]init];
                
                [self.navigationController pushViewController:loginVC animated:YES];
            }
            [self showHint:info];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull  error) {
        NSLog(@"====error:%@",error);
        [self hideHud];
        [self showHint:@"获取医生详情失败"];
    }];
    
    
}

#pragma mark - 病人评价列表
-(void)getCommentListData{
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:_userId,@"targetUserId",nil];
    
    [param setObject:static_sessionId forKey:@"sessionId"];
    NSLog(@"param = %@",param);
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_doctor_commentList parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSLog(@"responseObject = %@",responseObject);
        
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            [self showHint:@"获取医生评价列表失败"];
            NSLog(@"==dict:%@",data);
            return;
        }
        NSLog(@"==dict:%@",data);
        
        NSString * result = [NSString stringWithFormat:@"%@",[data objectForKey:@"result"]];
        if ([result isEqualToString:@"1"]) {
            NSDictionary *dic = [NSDictionary dictionaryWithDictionary:[data objectForKey:@"obj"]];
            _commentListArr = [NSMutableArray arrayWithArray:[dic objectForKey:@"result"]];
            NSLog(@"------obj = %@",_commentListArr);
            
            [self createCommentList];
            
        }else{
            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"msg"]];
            if ([info isEqualToString:msg_InvalidLoginInformation]) {
                
                [AppConfig removeUserInfo];
                
                [[EMClient sharedClient] logout:YES];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
                
                LoginViewController *loginVC = [[LoginViewController alloc]init];
                
                [self.navigationController pushViewController:loginVC animated:YES];
            }
            [self showHint:info];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull  error) {
        NSLog(@"====error:%@",error);
        [self hideHud];
        [self showHint:@"获取医生评价列表失败"];
    }];
    
    
}




#pragma mark - 添加和取消关注
-(void)addConcern{
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:_userId,@"targetUserId",nil];
    
    [param setObject:static_sessionId forKey:@"sessionId"];
    NSLog(@"param = %@",param);
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_collect_add parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSLog(@"responseObject = %@",responseObject);
        
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            [self showHint:@"添加关注失败"];
            NSLog(@"==dict:%@",data);
            return;
        }
        NSLog(@"==dict:%@",data);
        
        NSString * result = [NSString stringWithFormat:@"%@",[data objectForKey:@"result"]];
        if ([result isEqualToString:@"1"]) {
             [self.concernImage setHighlighted:YES];
             _isCollect = 1;
            
            _connectNumLabel.text = [NSString stringWithFormat:@"%ld",[_connectNumLabel.text integerValue] + 1];
            _concernBtn.enabled = YES;

        }else{
            _concernBtn.enabled = YES;

            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"msg"]];
            if ([info isEqualToString:msg_InvalidLoginInformation]) {
                
                [AppConfig removeUserInfo];
                
                [[EMClient sharedClient] logout:YES];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
                
                LoginViewController *loginVC = [[LoginViewController alloc]init];
                
                [self.navigationController pushViewController:loginVC animated:YES];
            }
            [self showHint:info];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull  error) {
        _concernBtn.enabled = YES;

        NSLog(@"====error:%@",error);
        [self hideHud];
        [self showHint:@"添加关注失败"];
    }];
    
    
}


-(void)deleteConcern{
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:_userId,@"targetUserId",nil];
    
    [param setObject:static_sessionId forKey:@"sessionId"];
    NSLog(@"param = %@",param);
    
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_collect_delete parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSLog(@"responseObject = %@",responseObject);
        
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            [self showHint:@"取消关注失败"];
            NSLog(@"==dict:%@",data);
            return;
        }
        NSLog(@"==dict:%@",data);
        
        NSString * result = [NSString stringWithFormat:@"%@",[data objectForKey:@"result"]];
        if ([result isEqualToString:@"1"]) {
             [self.concernImage setHighlighted:NO];
            _isCollect = 0;
             _connectNumLabel.text = [NSString stringWithFormat:@"%ld",[_connectNumLabel.text integerValue] - 1];
            _concernBtn.enabled = YES;

       
        }else{
            _concernBtn.enabled = YES;

            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"msg"]];
            if ([info isEqualToString:msg_InvalidLoginInformation]) {
                
                [AppConfig removeUserInfo];
                
                [[EMClient sharedClient] logout:YES];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
                
                LoginViewController *loginVC = [[LoginViewController alloc]init];
                
                [self.navigationController pushViewController:loginVC animated:YES];
            }
            [self showHint:info];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull  error) {
        _concernBtn.enabled = YES;

        NSLog(@"====error:%@",error);
        [self hideHud];
        [self showHint:@"取消关注失败"];
    }];
    
    
}


@end
